package com.ymatou.iapi.anlisettlement.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.anlisettlement.bean.AnliCatalogSettlementDetailBean;
import com.ymatou.iapi.anlisettlement.bean.AnliOrderBean;
import com.ymatou.iapi.anlisettlement.bean.AnliProductTypeEnum;
import com.ymatou.iapi.anlisettlement.bean.AnliSettlementTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.AnlihuiCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAnliOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.common.order.userquery.util.Utils;
import com.ymttest.database.model.anlihui.MemberRelation;
import com.ymttest.database.model.anlihui.Settlement;
import com.ymttest.database.model.anlihui.SettlementDetail;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.anlihui.FeeConfigWrapper;
import com.ymttest.database.sqlwapper.anlihui.MemberRelationWrapper;
import com.ymttest.database.sqlwapper.anlihui.SettlementDetailWrapper;
import com.ymttest.database.sqlwapper.anlihui.SettlementWrapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_AnliSettlement {

	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	YmtCatalogsIWapper wrapper = new YmtCatalogsIWapper();

	MemberRelationWrapper memberRelationWrapper = new MemberRelationWrapper();
	FeeConfigWrapper feeConfigWrapper = new FeeConfigWrapper();
	SettlementWrapper settlementWrapper = new SettlementWrapper();

	BigDecimal maxPlatFormRebateAmountPerProd = BigDecimal.ZERO;
	BigDecimal maxSellerRebateAmountPerProd = new BigDecimal("300.00");

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("安利会订单结算业务验证");
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@Before
	public void caseUp() {
		String accountid1;
		try {
			accountid1 = AccountCallServiceV2.getAccountId(20238699);
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
					9000000), new BigDecimal(0));
			
			accountid1 = AccountCallServiceV2.getAccountId(24635724);
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
					9000000), new BigDecimal(0));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("AnliSettlement");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 获得总结算收入
	 * 
	 * @param catalogSettmentDetailMap
	 *            规格的结算信息
	 * 
	 * @return
	 */
	private BigDecimal getTotalSettlementAmount(
			Map<String, AnliCatalogSettlementDetailBean> catalogSettmentDetailMap) {
		return catalogSettmentDetailMap.entrySet().stream()
				.map(Map.Entry::getValue).collect(Collectors.toList()).stream()
				.map(AnliCatalogSettlementDetailBean::getSettlementAmount)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
	}

	/**
	 * 获得总支付金额
	 * 
	 * @param catalogSettmentDetailMap
	 *            规格的结算信息
	 * 
	 * @return
	 */
	private BigDecimal getTotalPaidAmount(
			Map<String, AnliCatalogSettlementDetailBean> catalogSettmentDetailMap) {
		return catalogSettmentDetailMap.entrySet().stream()
				.map(Map.Entry::getValue).collect(Collectors.toList()).stream()
				.map(AnliCatalogSettlementDetailBean::getPaidAmount)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
	}

	/**
	 * 获取分润的管理费用或比例
	 * 
	 * @param anliCatalogSettlementDetailBean
	 * @param parentHunterLevel
	 * 
	 * @return
	 */
	private BigDecimal getManageServiceFee(int productType,
			int childMemberLevel, int parentMemberLevel) {
		Logger.debug("productType:"+productType+",childMemberLevel:"+childMemberLevel+",parentMemberLevel:"+parentMemberLevel);
		return feeConfigWrapper
				.selectFeeAmountByLevelAndType(childMemberLevel,
						parentMemberLevel, productType).getFee_amount()
				.multiply(new BigDecimal("0.01"));
	}
	
	/**
	 * 
	 * @param catalogSettlementMap
	 * @param orderId
	 * @param refundCatalogSettlementMap
	 * @return
	 */
	private Boolean getRefundCatalogMap(
			HashMap<String, AnliCatalogSettlementDetailBean> catalogSettlementMap,
			long orderId,
			HashMap<String, AnliCatalogSettlementDetailBean> refundCatalogSettlementMap) {

		Boolean isAllRefund = null;

		for (String catalogId : catalogSettlementMap.keySet()) {

			RefundBillPo refundBillPo = orderShardingWapper
					.selectRefundBillByOrderIdAndCatalogId(orderId, catalogId);

			// 如果该规格有产生退货退款单，则生成一个退货退款的明细
			if (null != refundBillPo
					&& refundBillPo.getRefundBillStatus() == 10
					&& refundBillPo.getRefundStatus() == 1) {

				AnliCatalogSettlementDetailBean refundAnliCatalogSettlementDetailBean = catalogSettlementMap
						.get(catalogId).deepClone();

				int refundCount = refundBillPo.getProductCount();

				if (refundCount == refundAnliCatalogSettlementDetailBean
						.getProductCount())
					isAllRefund = true;
				else
					isAllRefund = false;

				BigDecimal refundPerPaidAmount = refundBillPo.getTotalAmount()
						.divide(new BigDecimal(refundBillPo.getProductCount()), 2,
								BigDecimal.ROUND_HALF_UP);
				
				BigDecimal rate = refundPerPaidAmount.divide(
						refundAnliCatalogSettlementDetailBean
								.getPerPaidAmount(), MathContext.DECIMAL32);
				
				rate = rate.compareTo(BigDecimal.ONE) == 1 ? BigDecimal.ONE
						: rate;
				
				BigDecimal refundPerSettlementAmount = refundAnliCatalogSettlementDetailBean
						.getPerSettlementAmount().multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
				
				BigDecimal refundTotalSettlementAmount = refundPerSettlementAmount.multiply(
								new BigDecimal(refundCount));

				refundAnliCatalogSettlementDetailBean
						.setSettlementAmount(refundTotalSettlementAmount
								.negate());
				refundAnliCatalogSettlementDetailBean
						.setProductCount(refundCount);
				refundAnliCatalogSettlementDetailBean.setIsRefund(true);
				refundAnliCatalogSettlementDetailBean
						.setPerSettlementAmount(refundPerSettlementAmount
								.negate());
				refundAnliCatalogSettlementDetailBean
						.setPerPaidAmount(refundPerPaidAmount);

				refundCatalogSettlementMap.put(refundBillPo.getRefundBillNo(),
						refundAnliCatalogSettlementDetailBean);
			}
		}

		return isAllRefund;
	}

	/**
	 * 获得结算佣金
	 * 
	 * @param orderId
	 * @param level
	 *            hunter等级
	 * @param HunterCatalogSettlementDetailBean
	 *            推手规格结算明细
	 * @return
	 * @throws InterruptedException
	 */
	private AnliCatalogSettlementDetailBean getSettlementCommission(
			OrderDetailPo orderDetailPo, int memberLevel, int productType)
			throws InterruptedException {

		BigDecimal totalRebateAmount = BigDecimal.ZERO;
		BigDecimal singleCatalogPayableAmount = BigDecimal.ZERO;
		BigDecimal platformRebateRatio = BigDecimal.ZERO;
		BigDecimal actualRebateRatio = BigDecimal.ZERO;
		BigDecimal actualSellerRebateRatio = BigDecimal.ZERO;
		BigDecimal perTotalRebateAmount = BigDecimal.ZERO;

		int productCount = orderDetailPo.getProductCount();

		AnliCatalogSettlementDetailBean anliCatalogSettlementDetailBean = new AnliCatalogSettlementDetailBean();

		// 商品的实付金额
		BigDecimal payableAmount = TradingCallService
				.getOrderDetailPaidAmountExcludeFreight(orderDetailPo);

		// 单个商品的实付金额
		singleCatalogPayableAmount = payableAmount.divide(new BigDecimal(
				productCount), 32, RoundingMode.DOWN);

		if (productType == 1) {

			if (orderDetailPo.getSellerRebateRatio().compareTo(
					new BigDecimal("0.07")) == 1) {

				actualSellerRebateRatio = orderDetailPo.getSellerRebateRatio()
						.multiply(new BigDecimal("0.70"))
						.setScale(4, RoundingMode.HALF_DOWN);
				actualRebateRatio = orderDetailPo.getRebateRatio()
						.multiply(new BigDecimal("0.70"))
						.setScale(4, RoundingMode.HALF_DOWN);
			} else {

				actualSellerRebateRatio = orderDetailPo.getSellerRebateRatio();
				actualRebateRatio = orderDetailPo.getRebateRatio();
			}

			// 平台折扣
			platformRebateRatio = actualRebateRatio
					.subtract(actualSellerRebateRatio);

			// 单个商品的商家和平台返点金额
			BigDecimal perCatalogSellerRebateAmount = singleCatalogPayableAmount
					.multiply(actualSellerRebateRatio);
			BigDecimal perCatalogPlatformRebateAmount = singleCatalogPayableAmount
					.multiply(platformRebateRatio);

			// 商家返点最多100，平台返点最多30
			if (perCatalogSellerRebateAmount
					.compareTo(maxSellerRebateAmountPerProd) == 1)
				perCatalogSellerRebateAmount = maxSellerRebateAmountPerProd;

			if (perCatalogPlatformRebateAmount
					.compareTo(maxPlatFormRebateAmountPerProd) == 1)
				perCatalogPlatformRebateAmount = maxPlatFormRebateAmountPerProd;

			// 单个商品的总返点金额：平台返点+商家返点
			perTotalRebateAmount = perCatalogSellerRebateAmount.add(
					perCatalogPlatformRebateAmount).setScale(2,
					RoundingMode.DOWN);

		} else {
			// 会员第一级分润的childLevel始终为0，结算费用去除小数四舍五入
			actualRebateRatio = this.getManageServiceFee(productType, 0,
					memberLevel);
			perTotalRebateAmount = singleCatalogPayableAmount.multiply(
					actualRebateRatio).setScale(0, RoundingMode.HALF_UP);
		}

		totalRebateAmount = perTotalRebateAmount.multiply(new BigDecimal(
				productCount));

		anliCatalogSettlementDetailBean.setPaidAmount(payableAmount);
		anliCatalogSettlementDetailBean
				.setPerPaidAmount(singleCatalogPayableAmount.setScale(2,
						RoundingMode.DOWN));
		anliCatalogSettlementDetailBean.setSettlementAmount(totalRebateAmount);
		anliCatalogSettlementDetailBean
				.setPerSettlementAmount(perTotalRebateAmount);
		anliCatalogSettlementDetailBean.setRebateRatio(actualRebateRatio);
		anliCatalogSettlementDetailBean
				.setSellerRebateRatio(actualSellerRebateRatio);

		return anliCatalogSettlementDetailBean;
	}

	/**
	 * 获取安利结算type
	 * 
	 * @param anliProductTypeEnum
	 * @param index
	 * @param isRefund
	 * @return
	 */
	private AnliSettlementTypeEnum getAnliSettlementType(int productType,
			int index, boolean isRefund) {

		if (productType == 1 && index == 1 && isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_REFUND_FIRST_REBATE;
		else if (productType == 1 && index == 2 && isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_REFUND_SECOND_REBATE;
		else if (productType == 1 && index == 3 && isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_REFUND_THIRD_REBATE;
		else if (productType == 1 && index == 1 && !isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_FIRST_REBATE;
		else if (productType == 1 && index == 2 && !isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_SECOND_REBATE;
		else if (productType == 1 && index == 3 && !isRefund)
			return AnliSettlementTypeEnum.NORMAL_PRODUCT_THIRD_REBATE;

		else if (productType == 2 && index == 1 && isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_REFUND_FIRST_REBATE;
		else if (productType == 2 && index == 2 && isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_REFUND_SECOND_REBATE;
		else if (productType == 2 && index == 3 && isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_REFUND_THIRD_REBATE;
		else if (productType == 2 && index == 1 && !isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_FIRST_REBATE;
		else if (productType == 2 && index == 2 && !isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_SECOND_REBATE;
		else if (productType == 2 && index == 3 && !isRefund)
			return AnliSettlementTypeEnum.ANLI_MEMBER_THIRD_REBATE;

		else if (productType == 3 && index == 1 && isRefund)
			return AnliSettlementTypeEnum.DAREN_MEMBER_REFUND_FIRST_REBATE;
		else if (productType == 3 && index == 2 && isRefund)
			return AnliSettlementTypeEnum.DAREN_MEMBER_REFUND_SECOND_REBATE;
		else if (productType == 3 && index == 3 && isRefund)
			return AnliSettlementTypeEnum.DAREN_MEMBER_REFUND_THIRD_REBATE;
		else if (productType == 3 && index == 1 && !isRefund)
			return AnliSettlementTypeEnum.DAREN_MEMBER_FIRST_REBATE;
		else if (productType == 3 && index == 2 && !isRefund)
			return AnliSettlementTypeEnum.DAREN_MEMBER_SECOND_REBATE;
		else
			return AnliSettlementTypeEnum.DAREN_MEMBER_THIRD_REBATE;
	}

	/**
	 * 设置SettlementRemark
	 * 
	 * @param expectSettlement
	 * @param isLinkPayAnliOrder
	 *            （false：关联订单的原始订单，true：关联订单产生的新订单）
	 * @param isRefundAfterMember
	 */
	private void setSettlementStatusAndRemark(Settlement expectSettlement,
			Boolean isLinkPayAnliOrder, Boolean isRefundAfterMember,
			boolean needSettlement, OrderPo orderPo) {

		// 会员订单虚拟发货，结算速度快，默认结算成功
		// if (needSettlement || orderPo.getOrderType() == 2 ||
		// orderPo.getOrderType() == 3)
		// expectSettlement.setSettlement_status((byte) 1);

		if (null != isLinkPayAnliOrder) {

			if (!isLinkPayAnliOrder) {

				expectSettlement.setSettlement_status((byte) 2);

				if (null != isRefundAfterMember) {

					if (isRefundAfterMember && orderShardingWapper.isCancleOrder(orderPo))
						expectSettlement.setRemark("订单取消，作废");
					else if (isRefundAfterMember && !orderShardingWapper.isCancleOrder(orderPo))
						expectSettlement.setRemark("本人获得返点，作废原有结算单");
					else
						expectSettlement.setRemark("订单取消，作废");
				} else
					expectSettlement.setRemark("本人获得返点，作废原有结算单");

			} else {

				if (needSettlement)
					expectSettlement.setSettlement_status((byte) 1);
				else if (!needSettlement
						&& orderShardingWapper.isCancleOrder(orderPo))
					expectSettlement.setSettlement_status((byte) 2);
				else
					expectSettlement.setSettlement_status((byte) 0);

				if (expectSettlement.getSettlement_status() == 2)
					expectSettlement.setRemark("订单取消，作废");
				else
					expectSettlement.setRemark(null);
			}
		} else {

			// 会员商品由job确认结算
			if (Utils.zeroIfNull(orderPo.getOrderType()) > 0)
				expectSettlement.setSettlement_status((byte) 1);
			else {

				if (needSettlement)
					expectSettlement.setSettlement_status((byte) 1);
				else if (!needSettlement
						&& orderShardingWapper.isCancleOrder(orderPo))
					expectSettlement.setSettlement_status((byte) 2);
				else
					expectSettlement.setSettlement_status((byte) 0);
			}

			if (expectSettlement.getSettlement_status() == 2)
				expectSettlement.setRemark("订单取消，作废");
			else
				expectSettlement.setRemark(null);
		}
	}

	/**
	 * 计算分润的会员人数和等级
	 * 
	 * @param memberId
	 *            推手id（推荐人）
	 */
	private Map<Integer, MemberRelation> countMembers(long memberId) {

		Map<Integer, MemberRelation> resultMap = new LinkedHashMap<>();

		int index = 1;

		MemberRelation memberRelation = memberRelationWrapper
				.selectByMemberId(memberId);

		resultMap.put(index, memberRelation);

		while (null != memberRelation.getParent_id()
				&& memberRelation.getParent_id() != 0) {

			index = index + 1;

			if (index < 4) {

				MemberRelation parentHunterRelation = memberRelationWrapper
						.selectByMemberId(memberRelation.getParent_id());

				resultMap.put(index, parentHunterRelation);
				memberRelation = parentHunterRelation;
			} else {
				return resultMap;
			}
		}

		return resultMap;
	}

	private void verifyDb(long orderId, Long memberId, int memberOrderType,
			boolean needSettlement) throws ClientProtocolException,
			InterruptedException, IOException {

		this.verifyDb(orderId, memberId, memberOrderType, needSettlement, null,
				null);
	}

	/**
	 * 验证数据库
	 * 
	 * @param orderId
	 * @param memberId
	 * @param memberOrderType
	 *            订单类型（0：普通商品，1：体验会员，2：安利会员，3：海淘达人）
	 * @param needSettlement
	 *            是否需要结算
	 * @param isLinkPayAnliOrder
	 *            是否安利关联订单（false：关联订单的原始订单，true：关联订单产生的新订单）
	 * @param isRefundAfterMember
	 *            普通商品退货退款是否发生在购买会员之后
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	private void verifyDb(long orderId, Long memberId, int memberOrderType,
			Boolean needSettlement, Boolean isLinkPayAnliOrder,
			Boolean isRefundAfterMember) throws InterruptedException,
			ClientProtocolException, IOException {

		Thread.sleep(5000);

		if (Utils.zeroIfNull(memberId) == 0 && memberOrderType != 0) {

			Logger.verifyEquals(0, settlementWrapper.selectByOrderId(orderId)
					.size(), "无推荐人购买会员没有分润");
			return;
		}
		
		// 如果是会员类型或者需要结算
		if (memberOrderType > 0 || needSettlement) {

			settlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1), orderId);

			AnlihuiCallService.doRebateSettlement();

			Thread.sleep(5000);
		}

		// 校验结算表相关数据
		this.verifyMemberSettlementTable(orderId, memberId, memberOrderType,
				needSettlement, isLinkPayAnliOrder, isRefundAfterMember);
	}

	/**
	 * 验证MemberSettlementTable表
	 * 
	 * @param orderId
	 * @param memberId
	 * @param memberOrderType
	 *            订单类型（0：普通商品，1：体验会员，2：安利会员，3：海淘达人）
	 * @param needSettlement
	 *            是否需要结算
	 * @param isLinkPayAnliOrder
	 *            是否安利关联订单 （false：关联订单的原始订单，true：关联订单产生的新订单）
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	private void verifyMemberSettlementTable(long orderId, Long memberId,
			int memberOrderType, Boolean needSettlement,
			Boolean isLinkPayAnliOrder, Boolean isRefundAfterMember)
			throws InterruptedException, ClientProtocolException, IOException {

		Logger.comment("开始验证Settlement表orderId: " + orderId);

		BigDecimal totalSettlementAmount = BigDecimal.ZERO;
		BigDecimal totalPaidAmount = BigDecimal.ZERO;

		Boolean isAllRefund = null;
		int childLevel = 0;
		Long middleId = null;

		HashMap<String, AnliCatalogSettlementDetailBean> catalogSettlementMap = new HashMap<>();
		HashMap<String, AnliCatalogSettlementDetailBean> refundCatalogSettlementMap = new HashMap<>();

		OrderPo orderPo = orderShardingWapper.selectOrderbyOrderId(orderId);

		MemberRelation buyerMember = memberRelationWrapper
				.selectByMemberId(orderPo.getUserId());

		// if (memberOrderType == 0 && !isLinkPayAnliOrder) {
		//
		// if (null != orderShardingWapper
		// .selectOrderbyLinkPayanliOrderId(orderPo.getMainOrderId()))
		// isLinkPayAnliOrder = true;
		// }
		
		if (memberOrderType == 0) {
			
			if (null != buyerMember && null == isLinkPayAnliOrder && null == isRefundAfterMember)
				memberId = buyerMember.getMember_id();
			else if (null != isLinkPayAnliOrder || null != isRefundAfterMember) {

				// 如果购买者为会员，且购买会员商品后发生了普通商品的退货退款行为，则佣金由购买者获得
				if (null != buyerMember && memberOrderType == 0
						&& isLinkPayAnliOrder)
					memberId = buyerMember.getMember_id();
			}
		}

		// 邀请人即为贡献者
		Long contributionUserId = memberId;

		int productType = AnliProductTypeEnum.findEnumByOrderType(
				orderPo.getOrderType()).getCode();

		Map<Integer, MemberRelation> map = this.countMembers(memberId);

		for (Integer key : map.keySet()) {

			MemberRelation bean = map.get(key);

			Settlement expectSettlement = new Settlement();
			int memberLevel = bean.getMember_level();

			List<OrderDetailPo> orderDetailPoList = orderShardingWapper
					.selectOrderDetailbyOrderId(orderId);

			List<AnliCatalogSettlementDetailBean> anliCatalogSettlementDetailBeans = new ArrayList<>();

			// 如果是第一个人，则先计算商品的佣金
			if (key == 1) {

				for (OrderDetailPo orderDetailPo : orderDetailPoList) {

					AnliCatalogSettlementDetailBean anliCatalogSettlementDetailBean = new AnliCatalogSettlementDetailBean();

					if (productType == 1
							&& (null == orderDetailPo.getSellerRebateRatio() || null == orderDetailPo
									.getRebateRatio()))
						continue;
					else
						anliCatalogSettlementDetailBean = this
								.getSettlementCommission(orderDetailPo,
										memberLevel, productType);

					anliCatalogSettlementDetailBean
							.setOrderDetailPo(orderDetailPo);
					anliCatalogSettlementDetailBean.setOrderId(orderId);
					anliCatalogSettlementDetailBean
							.setProductCount(orderDetailPo.getProductCount());
					anliCatalogSettlementDetailBean.setProductType(productType);
					anliCatalogSettlementDetailBean.setIsRefund(false);

					catalogSettlementMap.put(orderDetailPo.getCatalogId(),
							anliCatalogSettlementDetailBean);

					anliCatalogSettlementDetailBeans
							.add(anliCatalogSettlementDetailBean);
					
					if (orderPo.getUserId() == contributionUserId) {
						
						DataUtil.verifyDecimalEquals(
								anliCatalogSettlementDetailBean
										.getSettlementAmount(), orderDetailPo
										.getOrderOwnerRebateAmount(), "验证orderDetail orderOwnerRebateAmount");
					}
				}
			} else {
				// 如果不是一级收佣者，则根据配置的比率重新设置分润
				for (String catalogId : catalogSettlementMap.keySet()) {

					AnliCatalogSettlementDetailBean anliCatalogSettlementDetailBean = catalogSettlementMap
							.get(catalogId);

					BigDecimal configRate = this.getManageServiceFee(
							productType, childLevel, memberLevel);
					BigDecimal perSettlementAmount = BigDecimal.ZERO;

					if (productType == 1)
						perSettlementAmount = anliCatalogSettlementDetailBean
								.getPerSettlementAmount().multiply(configRate)
								.setScale(2, RoundingMode.DOWN);
					else
						perSettlementAmount = anliCatalogSettlementDetailBean
								.getPerSettlementAmount().multiply(configRate)
								.setScale(0, RoundingMode.HALF_UP);

					anliCatalogSettlementDetailBean
							.setPerSettlementAmount(perSettlementAmount);
					anliCatalogSettlementDetailBean
							.setSettlementAmount(perSettlementAmount
									.multiply(new BigDecimal(
											anliCatalogSettlementDetailBean
													.getProductCount())));
					anliCatalogSettlementDetailBean.setRebateRatio(configRate);
					anliCatalogSettlementDetailBean.setSellerRebateRatio(null);

					catalogSettlementMap.put(catalogId,
							anliCatalogSettlementDetailBean);

					anliCatalogSettlementDetailBeans
							.add(anliCatalogSettlementDetailBean);
				}
			}

			// 获取总结算收入
			totalSettlementAmount = this
					.getTotalSettlementAmount(catalogSettlementMap);

			// 获取总支付金额
			if (productType == 1)
				totalPaidAmount = this.getTotalPaidAmount(catalogSettlementMap);
			else
				totalPaidAmount = this.getTotalPaidAmount(catalogSettlementMap)
						.add(orderPo.getFreight());

			if (null == isRefundAfterMember && null == isLinkPayAnliOrder) {

				isAllRefund = this.getRefundCatalogMap(catalogSettlementMap,
						orderId, refundCatalogSettlementMap);
			} else if (isLinkPayAnliOrder == null) {
				break;
			} else if (isRefundAfterMember == null && !isLinkPayAnliOrder) {
				break;
			} else if (isRefundAfterMember == null && isLinkPayAnliOrder) {
				isAllRefund = this.getRefundCatalogMap(catalogSettlementMap,
						orderId, refundCatalogSettlementMap);
			} else if (!isRefundAfterMember && !isLinkPayAnliOrder) {

				isAllRefund = this.getRefundCatalogMap(catalogSettlementMap,
						orderId, refundCatalogSettlementMap);
			} else if (isRefundAfterMember && isLinkPayAnliOrder) {

				isAllRefund = this.getRefundCatalogMap(catalogSettlementMap,
						orderId, refundCatalogSettlementMap);
			}

			long userId = bean.getMember_id();

			int settlementType = this.getAnliSettlementType(productType, key,
					false).getCode();

			// 支付结算单根据订单，一笔只有一条，退款结算单根据退款单号，一笔有多条
			int memberSettlementCount = 1 + refundCatalogSettlementMap.size();

			List<Settlement> memberSettlements = settlementWrapper
					.selectByOrderId(orderId)
					.stream()
					.filter(settlement -> settlement.getUser_id() == userId)
					.filter(settlement -> settlement.getContribution_user_id()
							.compareTo(contributionUserId) == 0)
					.collect(Collectors.toList());

			Collections.sort(memberSettlements,
					Comparator.comparing(Settlement::getSettlement_type));

			Logger.verifyEquals(
					memberSettlementCount,
					memberSettlements.size(),
					String.format("验证订单：%s，会员：%s 结算条数", orderId,
							bean.getMember_id()));

			// 验证收入settlement
			Settlement settlement = memberSettlements.get(0);

			Logger.comment("开始验证收入结算单：" + settlement.getSettlement_id());

			this.setSettlementStatusAndRemark(expectSettlement,
					isLinkPayAnliOrder, isRefundAfterMember, needSettlement,
					orderPo);
			
			if (null != isAllRefund && null != isLinkPayAnliOrder && null != isRefundAfterMember) {
				
				if (!isAllRefund && !isLinkPayAnliOrder && !isRefundAfterMember)
					expectSettlement.setRemark("本人获得返点，作废原有结算单");
			}

			expectSettlement.setBiz_no(String.valueOf(orderId));
			expectSettlement.setOrder_id(orderId);
			expectSettlement.setUser_id(userId);
			expectSettlement.setBuy_id(orderPo.getUserId());
			expectSettlement.setContribution_user_id(contributionUserId);
			expectSettlement.setMiddle_user_id(middleId);
			expectSettlement.setSettlement_amount(totalSettlementAmount
					.setScale(2, RoundingMode.HALF_UP));
			expectSettlement.setBiz_no(String.valueOf(orderId));
			expectSettlement.setPaid_amount(totalPaidAmount.setScale(2,
					RoundingMode.HALF_UP));
			expectSettlement.setSettlement_type((byte) settlementType);

			Logger.comment("开始验证settlementId: " + settlement.getSettlement_id());

			DataUtil.verify(expectSettlement.getOrder_id(),
					settlement.getOrder_id(), "验证Order_id");
			DataUtil.verify(expectSettlement.getUser_id(),
					settlement.getUser_id(), "验证User_id");
			DataUtil.verify(expectSettlement.getContribution_user_id(),
					settlement.getContribution_user_id(),
					"验证Contribution_user_id");
			DataUtil.verify(expectSettlement.getMiddle_user_id(),
					settlement.getMiddle_user_id(), "验证Middle_user_id");
			DataUtil.verify(expectSettlement.getBuy_id(),
					settlement.getBuy_id(), "验证Buy_id");
			DataUtil.verifyDecimalEquals(
					expectSettlement.getSettlement_amount(),
					settlement.getSettlement_amount(), "验证Settlement_amount");
			DataUtil.verify(expectSettlement.getBiz_no(),
					settlement.getBiz_no(), "验证Biz_no");
			
			DataUtil.verifyDecimalEquals(expectSettlement.getPaid_amount(),
					settlement.getPaid_amount(), "验证Paid_amount");
			DataUtil.verify(expectSettlement.getSettlement_type(),
					settlement.getSettlement_type(), "验证Settlement_type");
			
			if (expectSettlement.getSettlement_amount().compareTo(BigDecimal.ZERO) == 0) {
				
				DataUtil.verify("结算金额为0，已结算",
						settlement.getRemark(), "验证Remark");
				DataUtil.verify(1,
						settlement.getSettlement_status(), "验证Settlement_status");
			} else {
				
				DataUtil.verify(expectSettlement.getSettlement_status(),
						settlement.getSettlement_status(), "验证Settlement_status");
				DataUtil.verify(expectSettlement.getRemark(),
						settlement.getRemark(), "验证Remark");
			}

			if (needSettlement)
				verifyAccountEntry(settlement.getUser_id(),
						expectSettlement.getSettlement_type() < 20 ? "300045"
								: "300046", expectSettlement.getBiz_no(),
						expectSettlement.getSettlement_amount());

			// 验证结算明细表
			this.verifySettlementDetailTable(settlement.getSettlement_id(),
					anliCatalogSettlementDetailBeans);

			// 验证退款settlement
			if (refundCatalogSettlementMap.size() > 0) {

				for (String refundBillNo : refundCatalogSettlementMap.keySet()) {

					// 退款结算表只会对应一条结算明细表
					anliCatalogSettlementDetailBeans.clear();

					AnliCatalogSettlementDetailBean anliCatalogSettlementDetailBean = refundCatalogSettlementMap
							.get(refundBillNo);
//					settlement = memberSettlements.get(0);

					settlementType = this.getAnliSettlementType(productType,
							key, true).getCode();

					settlement = settlementWrapper
							.selectByOrderIdAndBizNoAndType(orderId,
									refundBillNo, settlementType);

					this.setSettlementStatusAndRemark(expectSettlement,
							isLinkPayAnliOrder, isRefundAfterMember, needSettlement,
							orderPo);
					
					if (null != isAllRefund && null != isLinkPayAnliOrder && null != isRefundAfterMember) {
						
						if (!isAllRefund && !isLinkPayAnliOrder && !isRefundAfterMember)
							expectSettlement.setRemark("本人获得返点，作废原有结算单");
					}

					expectSettlement.setBiz_no(String.valueOf(orderId));
					expectSettlement.setOrder_id(orderId);
					expectSettlement.setUser_id(userId);
					expectSettlement
							.setContribution_user_id(contributionUserId);
					expectSettlement.setMiddle_user_id(middleId);
					expectSettlement.setBuy_id(orderPo.getUserId());
					expectSettlement
							.setSettlement_amount(anliCatalogSettlementDetailBean
									.getSettlementAmount().setScale(2,
											RoundingMode.HALF_UP));
					expectSettlement.setBiz_no(refundBillNo);
					expectSettlement.setPaid_amount(totalPaidAmount.setScale(2,
							RoundingMode.HALF_UP));
					expectSettlement.setSettlement_type((byte) settlementType);
					
					if (expectSettlement.getSettlement_amount().compareTo(BigDecimal.ZERO) == 0)
						expectSettlement.setRemark("结算金额为0，已结算");

					Logger.comment("开始验证退款结算单：" + settlement.getSettlement_id());

					DataUtil.verify(expectSettlement.getOrder_id(),
							settlement.getOrder_id(), "验证Order_id");
					DataUtil.verify(expectSettlement.getUser_id(),
							settlement.getUser_id(), "验证User_id");
					DataUtil.verify(expectSettlement.getContribution_user_id(),
							settlement.getContribution_user_id(),
							"验证Contribution_user_id");
					DataUtil.verify(expectSettlement.getMiddle_user_id(),
							settlement.getMiddle_user_id(), "验证Middle_user_id");
					DataUtil.verify(expectSettlement.getBuy_id(),
							settlement.getBuy_id(), "验证Buy_id");
					DataUtil.verifyDecimalEquals(
							expectSettlement.getSettlement_amount(),
							settlement.getSettlement_amount(),
							"验证Settlement_amount");
					DataUtil.verify(expectSettlement.getBiz_no(),
							settlement.getBiz_no(), "验证Biz_no");
					DataUtil.verify(expectSettlement.getSettlement_status(),
							settlement.getSettlement_status(),
							"验证Settlement_status");
					DataUtil.verifyDecimalEquals(
							expectSettlement.getPaid_amount(),
							settlement.getPaid_amount(), "验证Paid_amount");
					DataUtil.verify(expectSettlement.getSettlement_type(),
							settlement.getSettlement_type(),
							"验证Settlement_type");
					DataUtil.verify(expectSettlement.getRemark(),
							settlement.getRemark(), "验证Remark");

					if (needSettlement
							&& expectSettlement.getSettlement_amount()
									.compareTo(BigDecimal.ZERO) != 0)
						verifyAccountEntry(
								settlement.getUser_id(),
								expectSettlement.getSettlement_type() < 20 ? "300045"
										: "300046",
								expectSettlement.getBiz_no(),
								expectSettlement.getSettlement_amount());

					anliCatalogSettlementDetailBeans
							.add(anliCatalogSettlementDetailBean);

					// 验证结算明细表，退款明细
					this.verifySettlementDetailTable(
							settlement.getSettlement_id(),
							anliCatalogSettlementDetailBeans);
				}
			}

			childLevel = memberLevel;

			if (key == 2)
				middleId = bean.getMember_id();
		}

		// 如果是会员订单，查找是否有关联的普通商品订单
		if (memberOrderType > 0) {

			Long linkPayAnliOrderId = orderPo.getLinkPayAnliOrderId();

			if (linkPayAnliOrderId != null && linkPayAnliOrderId > 0) {

				List<OrderPo> linkPayAnliOrders = orderShardingWapper
						.selectOrderbyMainOrderId(linkPayAnliOrderId)
						.stream()
						.filter(linkPayAnliOrderPo -> null != linkPayAnliOrderPo
								.getOrderType()
								&& linkPayAnliOrderPo.getOrderType() == 0)
						.collect(Collectors.toList());
				
				if (linkPayAnliOrders.size() > 0) {

					for (int i = 0; i < linkPayAnliOrders.size(); i++) {

						OrderPo linkPayAnliOrder = linkPayAnliOrders.get(i);

						Logger.comment("验证linkPayAnliOrders: "
								+ linkPayAnliOrder.getOrderId());
						
						if (null == isRefundAfterMember || isRefundAfterMember) {
							
							this.verifyMemberSettlementTable(
									linkPayAnliOrder.getOrderId(),
									linkPayAnliOrder.getShareUserId(),
									linkPayAnliOrder.getOrderType(),
									linkPayAnliOrder.getOrderStatus() == 4 ? true
											: false, true,
									isRefundAfterMember);
						} else {
							
							List<Settlement> memberSettlements = settlementWrapper
									.selectByOrderId(orderId)
									.stream()
									.filter(settlement -> settlement
											.getUser_id() == linkPayAnliOrder
											.getUserId())
									.collect(Collectors.toList());

							Logger.verifyEquals(0,
									memberSettlements.size(),
									"如果在购买会员前，普通商品发生了退款，不产生新的订单");
						}
					}
				}
			}
		}
	}

	private void verifyAccountEntry(long userId, String bizCode,
			String originalNo, BigDecimal settlementAmount) {

		AccountWapper accountWapper = new AccountWapper();

		HashMap<String, Object> accountEntryMap = new HashMap<>();

		accountEntryMap.put("userId", userId);
		accountEntryMap.put("bizcode", bizCode);
		accountEntryMap.put("originalNo", originalNo);

		DataUtil.verifyDecimalEquals(settlementAmount, accountWapper
				.selectAccountEntryByMap(accountEntryMap).get(0).getAmount(),
				"验证accountEntry日志记录");
	}

	/**
	 * 校验SettlementDetail
	 * 
	 * @param orderId
	 * @param catalogSettmentDetailMap
	 *            规格结算明细
	 * @throws InterruptedException
	 */
	private void verifySettlementDetailTable(
			String settlementId,
			List<AnliCatalogSettlementDetailBean> anliCatalogSettlementDetailBeans)
			throws InterruptedException {

		Logger.comment(String.format("开始验证SettlementDetail表, %s管理费明细",
				settlementId));

		SettlementDetailWrapper settlementDetailWrapper = new SettlementDetailWrapper();

		for (AnliCatalogSettlementDetailBean anliCatalogSettlementDetailBean : anliCatalogSettlementDetailBeans) {

			String catalogId = anliCatalogSettlementDetailBean
					.getOrderDetailPo().getCatalogId();

			Logger.comment(String.format("开始验证settlementId：%s, catalogId: %s",
					settlementId, catalogId));

			SettlementDetail actualPo = settlementDetailWrapper
					.selectBySettlementIdAndCatalogId(settlementId, catalogId);

			SettlementDetail expectPo = new SettlementDetail();

			expectPo.setSettlement_id(settlementId);
			expectPo.setProduct_id(anliCatalogSettlementDetailBean
					.getOrderDetailPo().getProductId());
			expectPo.setCatalog_id(catalogId);
			expectPo.setPer_paid_amount(anliCatalogSettlementDetailBean
					.getPerPaidAmount());
			expectPo.setTotal_settlement_amount(anliCatalogSettlementDetailBean
					.getSettlementAmount());
			expectPo.setProduct_num(anliCatalogSettlementDetailBean
					.getProductCount());
			expectPo.setPer_settlement_amout(anliCatalogSettlementDetailBean
					.getPerSettlementAmount());
			expectPo.setOrder_id(anliCatalogSettlementDetailBean.getOrderId());
			expectPo.setProduct_type((byte) anliCatalogSettlementDetailBean
					.getProductType());
			expectPo.setRebate_ratio(anliCatalogSettlementDetailBean
					.getRebateRatio());
			expectPo.setSeller_rebate_ratio(anliCatalogSettlementDetailBean
					.getSellerRebateRatio());

			DataUtil.verify(expectPo.getSettlement_id(),
					actualPo.getSettlement_id(), "验证Settlement_id");
			DataUtil.verify(expectPo.getProduct_id(), actualPo.getProduct_id(),
					"验证Product_id");
			DataUtil.verify(expectPo.getCatalog_id(), actualPo.getCatalog_id(),
					"验证Catalog_id");
			DataUtil.verify(expectPo.getPer_paid_amount(),
					actualPo.getPer_paid_amount(), "验证Per_paid_amount");
			DataUtil.verify(expectPo.getTotal_settlement_amount(),
					actualPo.getTotal_settlement_amount(),
					"验证Total_settlement_amount");
			DataUtil.verify(expectPo.getProduct_num(),
					actualPo.getProduct_num(), "验证Product_num");
			DataUtil.verify(expectPo.getPer_settlement_amout(),
					actualPo.getPer_settlement_amout(),
					"验证Per_settlement_amout");
			DataUtil.verify(expectPo.getOrder_id(), actualPo.getOrder_id(),
					"验证Order_id");
			DataUtil.verify(expectPo.getProduct_type(),
					actualPo.getProduct_type(), "验证Product_type");
			DataUtil.verify(expectPo.getRebate_ratio(),
					actualPo.getRebate_ratio(), "验证Rebate_ratio");

			// 如果是退款单明细，一个settlementId只会有一条明细数据
			if (anliCatalogSettlementDetailBean.getIsRefund())
				break;
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_001() {
		Logger.start(true, "正常购买一份安利会员商品,未结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 20226434;
			int memberOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, new BigDecimal("5.5"), false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_002() {
		Logger.start(true, "正常购买一份海淘达人会员商品,未结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_003() {
		Logger.start(true, "正常购买一份普通商品,未结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_004() {
		Logger.start(true, "正常购买普通商品, 两个商品均未设置返点比率，未结算，没有任何结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, 20238699, LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			SettlementWrapper wrapper = new SettlementWrapper();

			Logger.verifyEquals(0, wrapper.selectByOrderId(orderId).size(),
					"验证settlement列表");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_005() {
		Logger.start(true, "正常购买一份海淘达人会员, 已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_006() {
		Logger.start(true, "正常购买一份普通商品,已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_007() {
		Logger.start(true, "正常购买一份普通商品,两个商品，其中一个设置了返点比率，一个未设置，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType, false);

			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_008() {
		Logger.start(true, "正常购买一份普通商品,两个商品均设置了返点比率，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_009() {
		Logger.start(true, "正常购买一份普通商品,确认收货前，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_010() {
		Logger.start(true, "正常购买多份普通商品,确认收货前，商品部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.ZERO, false,
							memberId, memberOrderType);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	// 自动发货，无法取消订单，特殊case
	public void Tc_AnliSettlement_011() {
		Logger.start(true, "正常购买一份安利会员商品,确认收货前，客服取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 3;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.ZERO, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 取消订单
			AnlihuiCallService.anliOrderCancel(orderId, userId);

			Thread.sleep(4000);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_012() {
		Logger.start(true, "正常购买一份普通商品,确认收货后，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			
			int userId = new OrderCallService().createNewUser();

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.TEN, false, memberId,
							memberOrderType);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_013() {
		Logger.start(true, "正常购买多份普通商品,确认收货后，商品部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			int userId = new OrderCallService().createNewUser();

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.TEN, false, memberId,
							memberOrderType);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_015() {
		Logger.start(true, "购买安利会员，邀请人为安利会员，会员订单计费规则（三层级别）");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A3<-B1
		 * 
		 * 3、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, daren_member_List.get(2));

			long memberId = anli_member_list.get(0);
			int memberOrderType = 2;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_016() {
		Logger.start(true, "购买海淘达人会员，邀请人为安利会员，会员订单计费规则（三层级别）");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A2<-B1
		 * 
		 * 3、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, daren_member_List.get(1));

			long memberId = anli_member_list.get(0);
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_017() {
		Logger.start(true, "购买海淘达人会员，邀请人为安利会员，会员订单计费规则（三层级别）,只有一个上级");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A1<-B1
		 * 
		 * 3、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// int userId = 25304624;

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, daren_member_List.get(0));

			long memberId = anli_member_list.get(0);

			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_018() {
		Logger.start(true, "购买安利会员，邀请人为安利会员，会员订单计费规则（两层级别）");
		/**
		 *
		 * 1、B1为安利会员
		 * 
		 * 3、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, 0);

			long memberId = anli_member_list.get(0);
			int memberOrderType = 2;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_019() {
		Logger.start(true, "购买安利会员，邀请人为海淘达人，会员订单计费规则（两层级别）");
		/**
		 *
		 * 1、A1、A2、A3、A4为海淘达人，上线关系为A1<-A2<-A3<-A4
		 * 
		 * 2、A4邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 4, 0);

			long memberId = daren_member_List.get(3);
			int memberOrderType = 2;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_020() {
		Logger.start(true, "购买海淘达人会员，邀请人为海淘达人，会员订单计费规则（两层级别）");
		/**
		 *
		 * 1、A1、A2、A3、A4为海淘达人，上线关系为A1<-A2<-A3<-A4
		 * 
		 * 2、A2邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 4, 0);

			long memberId = daren_member_List.get(1);
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_021() {
		Logger.start(true, "购买海淘达人会员，邀请人为海淘达人，会员订单计费规则（两层级别），没有上级");
		/**
		 *
		 * 1、A1、A2、A3、A4为海淘达人，上线关系为A1<-A2<-A3<-A4
		 * 
		 * 2、A1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);

			long memberId = daren_member_List.get(0);
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_022() {
		Logger.start(true, "购买安利会员，无邀请人");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			int memberOrderType = 2;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, 0L, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_023() {
		Logger.start(true, "购买普通商品，邀请人为安利会员，会员订单计费规则（三层级别）");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A3<-B1
		 * 
		 * 3、B1邀请P购买普通商品
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, daren_member_List.get(2));

			long memberId = anli_member_list.get(0);
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_024() {
		Logger.start(true, "购买普通商品，邀请人为海淘达人，会员订单计费规则（两层级别）");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、A2邀请P购买普通商品
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);

			long memberId = daren_member_List.get(1);
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_025() {
		Logger.start(true, "购买普通商品，邀请人为海淘达人，会员订单计费规则（两层级别）,无上级");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、A1邀请P购买普通商品
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);

			long memberId = daren_member_List.get(0);
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_026() {
		Logger.start(true, "安利会员自购商品,无上级");
		/**
		 *
		 * 1、B1为安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			AnlihuiCallService.insertAnlihuiMember(userId, 2, 0);

			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							(long) userId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, (long)userId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_027() {
		Logger.start(true, "海淘达人自购商品，前面有3个上级");
		/**
		 *
		 * 1、A1、A2、A3、A4为海淘达人，上线关系为A1<-A2<-A3<-A4
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 4, 0);

			AnlihuiCallService.insertAnlihuiMember(userId, 3,
					daren_member_List.get(2));
			// AnlihuiCallService.insertAnlihuiMember(userId, 3, 0);

			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							(long) userId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, (long)userId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_028() {
		Logger.start(true, "安利会员自购商品，前面有1个上级");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A1<-B1
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);

			AnlihuiCallService.insertAnlihuiMember(userId, 2,
					daren_member_List.get(0));

			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							(long) userId, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, (long)userId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_029() {
		Logger.start(true, "正常购买一份普通商品,买手返点比率等于7%，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.ZERO, false, 0, Arrays
							.asList(new BigDecimal("0.0700"), new BigDecimal(
									"0.1982")));
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_030() {
		Logger.start(true, "正常购买一份普通商品,每商品的平台和买手返点总额大于300，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMaxRebateAmountAnlihuiOrder(BigDecimal.ZERO,
							memberId, 0, Arrays.asList(
									new BigDecimal("0.0700"), new BigDecimal(
											"0.0900")));
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_031() {
		Logger.start(true, "邀请人为安利会员，第一笔订单那购买一份普通商品,未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			Thread.sleep(5000);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 2);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_032() {
		Logger.start(true, "邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			Thread.sleep(5000);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_033() {
		Logger.start(true,
				"邀请人为海淘达人，第一笔订单购买一份普通商品,未结算，全部退货退款，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");
			
			Thread.sleep(10000);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, false);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_034() {
		Logger.start(true,
				"邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，部分退货退款，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");
			
			Thread.sleep(5000);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, false);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_035() {
		Logger.start(true, "邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，取消订单，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderCancel(orderId, userId);

			Thread.sleep(4000);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, false);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_036() {
		Logger.start(true,
				"邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，第二笔订单购买会员，第一个订单全部退货退款，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, true);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_037() {
		Logger.start(true,
				"邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，第二笔订单购买会员，第一笔部分退货退款，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, true);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_038() {
		Logger.start(true,
				"邀请人为海淘达人，第一笔订单那购买一份普通商品,未结算，第二笔订单购买会员，取消第一笔订单，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long tradingId2 = placeOrder2.getTradingId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderCancel(orderId, userId);

			Thread.sleep(4000);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, true);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_039() {
		Logger.start(true, "一笔主订单包含会员订单组和普通商品订单组，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiMemberAndAnlihuiNormalOrderGroup(userId,
							memberId, memberOrderType);

			placeOrder.getMainOrderId();

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);

			Thread.sleep(10000);

			List<OrderPo> orderPoList = orderShardingWapper
					.selectOrderbyMainOrderId(placeOrder.getMainOrderId());

			OrderPo productOrderPo = orderPoList.stream()
					.filter(orderPo -> orderPo.getOrderType() == 0)
					.collect(Collectors.toList()).get(0);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(productOrderPo.getOrderId());
			productBean.setMemberOrderType(productOrderPo.getOrderType());

			OrderPo memberOrderPo = orderPoList.stream()
					.filter(orderPo -> orderPo.getOrderType() == 3)
					.collect(Collectors.toList()).get(0);

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(memberOrderPo.getOrderId());
			memberBean.setMemberOrderType(memberOrderPo.getOrderType());

			AnlihuiCallService.createMember(memberOrderPo.getOrderId(), userId,
					memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId,
					memberOrderPo.getOrderId());

			Thread.sleep(4000);

			Logger.comment("前置数据准备结束");

			Logger.comment(String.format("orderId1: %s, orderId2:%s",
					productBean.getOrderId(), memberOrderPo.getOrderId()));

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_040() {
		Logger.start(true,
				"邀请人为安利会员，第一笔订单包含两个商品，一个为返点商品，一个为非返点商品，未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(userId, memberId, 0, false);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 2);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_041() {
		Logger.start(true, "邀请人为海淘达人会员，第一笔订单包含两个商品，均为返点商品，未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(userId, memberId, 0, true);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.insertAnlihuiMember(userId, 2, memberId);
			
			Thread.sleep(3000);
			
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");			
			Thread.sleep(5000);
			
			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_042() {
		Logger.start(true,
				"邀请人为安利会员，第一笔包含两个订单，一个订单有多个返点商品，一个订单无返点商品，未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiMultiOrder(userId, memberId, false);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.createMember(orderId2, userId, memberId, 2);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_043() {
		Logger.start(true,
				"邀请人为海淘达人会员，第一笔包含两个订单，两个订单均有返点商品，未结算，第二笔订单购买会员，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiMultiOrder(userId, memberId, true);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean1 = new AnliOrderBean();

			productBean1.setMemberId(memberId);
			productBean1.setOrderId(orderId);
			productBean1.setMemberOrderType(memberOrderType);
			
			AnliOrderBean productBean2 = new AnliOrderBean();

			productBean2.setMemberId(memberId);
			productBean2.setOrderId(placeOrder.getOrderList().get(1).getOrderId());
			productBean2.setMemberOrderType(memberOrderType);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							memberId, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.insertAnlihuiMember(userId, 2, memberId);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean1.getOrderId(), productBean1.getMemberId(),
					productBean1.getMemberOrderType(), false, false, null);
			
			verifyDb(productBean2.getOrderId(), productBean2.getMemberId(),
					productBean2.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_044() {
		Logger.start(true, "一笔主订单包含会员订单和普通商品订单，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 3;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiMemberAndAnlihuiNormalOrder(userId, memberId,
							memberOrderType);

			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);

			Thread.sleep(10000);

			List<OrderPo> orderPoList = orderShardingWapper
					.selectOrderbyMainOrderId(placeOrder.getMainOrderId());

			OrderPo productOrderPo = orderPoList.stream()
					.filter(orderPo -> orderPo.getOrderType() == 0)
					.collect(Collectors.toList()).get(0);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(productOrderPo.getOrderId());
			productBean.setMemberOrderType(productOrderPo.getOrderType());

			OrderPo memberOrderPo = orderPoList.stream()
					.filter(orderPo -> orderPo.getOrderType() == 3)
					.collect(Collectors.toList()).get(0);

			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(memberId);
			memberBean.setOrderId(memberOrderPo.getOrderId());
			memberBean.setMemberOrderType(memberOrderPo.getOrderType());

			AnlihuiCallService.createMember(memberOrderPo.getOrderId(), userId, memberId, 3);
			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId,
					memberOrderPo.getOrderId());

			Thread.sleep(4000);

			Logger.comment("前置数据准备结束");

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_045() {
		Logger.start(true, "会员自购普通商品,不传入memberId，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long memberId = null;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.ZERO, false, null,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_046() {
		Logger.start(true, "购买安利会员，邀请人为安利会员，不传入memberId,会员订单计费规则（三层级别）");
		/**
		 *
		 * 1、A1、A2、A3为海淘达人，上线关系为A1<-A2<-A3
		 * 
		 * 2、B1为安利会员，上线关系为A3<-B1
		 * 
		 * 3、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> daren_member_List = AnlihuiCallService
					.buildAnlihuiMemberRelation(3, 3, 0);
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, daren_member_List.get(2));

			long memberId = anli_member_list.get(0);
			int memberOrderType = 2;

			// 先创建邀请关系，验证时使用此memberId
			AnlihuiCallService.insertInviteRelation(userId, memberId);
			
			// 创建绑定关系
			AnlihuiCallService.insertAnlihuiMember(userId, 2, memberId);

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_047() {
		Logger.start(true, "购买安利会员，邀请人为安利会员，不传入memberId,会员订单计费规则（两层级别）");
		/**
		 *
		 * 1、B1为安利会员
		 * 
		 * 2、B1邀请P购买安利会员
		 */
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			// 构建memberRelation
			List<Long> anli_member_list = AnlihuiCallService
					.buildAnlihuiMemberRelation(2, 1, 0);

			long memberId = anli_member_list.get(0);
			int memberOrderType = 2;

			// 先创建邀请关系，验证时使用此memberId
			AnlihuiCallService.insertInviteRelation(userId, memberId);
			
			// 创建绑定关系
			AnlihuiCallService.insertAnlihuiMember(userId, 2, memberId);

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType);
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_048() {
		Logger.start(true,
				"邀请人为海淘达人会员，第一笔订单包含两个商品，均为返点商品，无邀请人，未结算，第二笔订单购买会员，无邀请关系，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

//			long memberId = 3002;
			int memberOrderType = 0;

			// // 先创建邀请关系
			// AnlihuiCallService.insertInviteRelation(userId, memberId);

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(userId, null, 0, true);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(null);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 2;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);
			
			// 创建绑定关系
			AnlihuiCallService.insertAnlihuiMember(userId, 2, 0);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			memberBean.setMemberId(null);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			// 第一笔会员订单没有邀请人，不会产生旧订单，直接校验新订单
			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, true, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_049() {
		Logger.start(true,
				"邀请人为海淘达人会员，第一笔订单包含两个商品，均为返点商品，无邀请人，未结算，第二笔订单购买会员，有邀请关系,验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(userId, null, 0, true);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(null);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 2;
			
			// 先创建邀请关系
			AnlihuiCallService.insertInviteRelation(userId, memberId);

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			AnlihuiCallService.createMember(orderId2, userId, 3002,
					memberOrderType);

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			// 邀请关系即为shareUserId
			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			// 第一笔会员订单没有邀请人，不会产生旧订单，直接校验新订单
			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, true, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_050() {
		Logger.start(true,
				"邀请人为海淘达人会员，第一笔订单包含两个商品，均为返点商品，未结算，第二笔订单购买会员，无邀请关系,验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderCallService = new OrderCallService();
			int userId = orderCallService.createNewUser();

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(userId, memberId, 0, true);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);
			
			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			memberOrderType = 3;

			TradingServiceResp placeOrder2 = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder((long) userId, BigDecimal.ZERO, false,
							null, memberOrderType, tradingId);
			long orderId2 = placeOrder2.getOrderList().get(0).getOrderId();
			long sellerId2 = placeOrder2.getOrderList().get(0).getSellerId();
			long tradingId2 = placeOrder2.getTradingId();
			BigDecimal totalPrice2 = placeOrder2.getPayableAmount();

			Long thirdTradingId2 = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId2, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId2.toString(),
					totalPrice2.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId2);

			AnlihuiCallService.onOrderPay(memberOrderType, userId, sellerId2,
					orderId2);

			Logger.comment(String.format("orderId1: %s, orderId2:%s", orderId,
					orderId2));

			Logger.comment("前置数据准备结束");
			
			AnliOrderBean memberBean = new AnliOrderBean();

			// 如果会员订单没有shareUserId，则使用普通商品订单的shareUserId
			memberBean.setMemberId(memberId);
			memberBean.setOrderId(orderId2);
			memberBean.setMemberOrderType(memberOrderType);

			verifyDb(productBean.getOrderId(), productBean.getMemberId(),
					productBean.getMemberOrderType(), false, false, null);

			// 用例执行较慢，会员订单已经由job结算
			verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
					memberBean.getMemberOrderType(), true, null, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_051() {
		Logger.start(true,
				"邀请人为海淘达人，一笔订单购买一份安利普通商品和普通商品,未结算，全部退货退款,验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.ZERO, false,
							memberId, memberOrderType, false);

			long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");
			
			Thread.sleep(10000);
			
			verifyDb(orderId, memberId, memberOrderType, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_052() {
		Logger.start(true,
				"邀请人为海淘达人，一笔订单购买一份安利普通商品和普通商品,已结算，全部退货退款,验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 3002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.ZERO, false,
							memberId, memberOrderType, false);

			long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(), userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);
			
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			AnliOrderBean productBean = new AnliOrderBean();

			productBean.setMemberId(memberId);
			productBean.setOrderId(orderId);
			productBean.setMemberOrderType(memberOrderType);

			Logger.comment("前置数据准备结束");
			
			Thread.sleep(10000);

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_053() {
		Logger.start(true, "正常购买多份普通商品,确认收货后，商品退款1件, 退款金额1件商品金额+1元");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			int userId = new OrderCallService().createNewUser();

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.TEN, false, memberId,
							memberOrderType);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			BigDecimal applyRefundAmount = placeOrder.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getProductPrice();
			
			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1, applyRefundAmount.add(BigDecimal.ONE));

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AnliSettlement_054() {
		Logger.start(true, "正常购买多份普通商品,确认收货后，退款金额1元");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			int userId = new OrderCallService().createNewUser();

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(userId, BigDecimal.TEN, false, memberId,
							memberOrderType);
			
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);
			
			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0, BigDecimal.ONE);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			verifyDb(orderId, memberId, memberOrderType, true);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public static void main(String[] args) throws Exception {

		Ts_AnliSettlement test = new Ts_AnliSettlement();
//
		test.verifyDb(1520113482L, 2002L, 0, true, null, null);
		
//		// 第一笔会员订单没有邀请人，不会产生旧订单，直接校验新订单
//		verifyDb(productBean.getOrderId(), productBean.getMemberId(),
//				productBean.getMemberOrderType(), false, true, null);
		
//		AnliOrderBean productBean = new AnliOrderBean();
//
//		productBean.setMemberId(3002L);
//		productBean.setOrderId(1520023456);
//		productBean.setMemberOrderType(0);
//
//		AnliOrderBean memberBean = new AnliOrderBean();
//
//		memberBean.setMemberId(3002L);
//		memberBean.setOrderId(1520033456);
//		memberBean.setMemberOrderType(3);
//
//		List<AnliOrderBean> anliOrderList = new ArrayList<>();
//
//		anliOrderList.add(productBean);
//		anliOrderList.add(memberBean);
//		
//		test.verifyDb(productBean.getOrderId(), productBean.getMemberId(),
//				productBean.getMemberOrderType(), false, false, false);
//
//		// 用例执行较慢，会员订单已经由job结算
//		test.verifyDb(memberBean.getOrderId(), memberBean.getMemberId(),
//				memberBean.getMemberOrderType(), true, null, false);
	}
}
